/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package trastienda.servlet.relacion;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import trastienda.dao.RelacionDAO;
import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Relacion;

/**
 *
 * @author Anthony
 */
public class RelacionInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public RelacionInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//
		String a = request.getParameter("id_usuario");
		String b = request.getParameter("id_hard");
		String c = request.getParameter("fecha_alta");
		String d = request.getParameter("fecha_baja");
		String e = request.getParameter("estado");


		Relacion vo = new Relacion();
		vo.setUsuarios_id(a);
		vo.setHardware_id(b);
		vo.setFecha_alta(c);
		vo.setFecha_baja(d);
                vo.setEstado(e);


		RelacionDAO dao = new RelacionDAO();
		try {
			dao.insertar(vo);
			RequestDispatcher rd = request
					.getRequestDispatcher("/relaciones_inventario.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}

	}
}